package com.example.edianzu.somur.utils.content;

import android.Manifest;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;

/**
 * author：风不会停息 on 2017/7/17 12:02
 * mailbox：yh131412hys@163.com
 * project：Somur
 * tel：13295355900
 * describe：
 */

public class CallPhone extends Application {

    /**
     * 调用拨号界面
     * @param phone 电话号码
     */
    public static void call(String phone, Context context) {

        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    /**
     * 调用拨号功能
     * @param phone 电话号码
     */
    public void callNumber(String phone, Context context) {
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        context.startActivity(intent);
    }
}
